<template>
    <div class="login">
        <h2>登陆</h2>
        <van-cell-group>
            <van-field v-model="phoneNumber" required clearable label="用户名"  placeholder="请输入用户名"/>

            <van-field v-model="password" type="password" label="密码" placeholder="请输入密码" required />
        </van-cell-group>

        <van-button type="default" size="large" @click="login">登陆</van-button>

        <div class="other">
            <span>忘记密码</span>
            <span>注册账号</span>
        </div>
    </div>
</template>

<script>
import LOGIN_API from '@/api/login'
export default {
    data(){
        return{
            phoneNumber: '',
            password: '',
        }
    },
    methods:{
        login(){
            let phoneNumber = this.phoneNumber
            let password = this.password
            let data = {
                phoneNumber,
                password
            }
            LOGIN_API.login(data)
            .then(res => {
                
                if(res.code == 200){
                    sessionStorage.setItem('token', res.data.token)
                    
                    this.$router.push({name:'home'})
                }else this.$toast(res.message)
            })
        }
    }
}
</script>

<style scoped>
.other{
    display:flex;
    justify-content: space-between;

    margin-top:10px;
}
.login{
    padding:10px;
    background-color:white;
}
</style>